home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / A-B / 2 Panes.cpt / How to do 2 Panes.Doc next >
Text File  |  1990-09-21  |  6KB  |  223 lines

  1.   {I needed to implement a spreasheet-style interface, in which two panes were enclosed in a single}
  2. {window.  One of the two panes scrolled horizontally and vertically; the other pane scrolled only}
  3. {horizontally, and was fixed vertically.}
  4. {}
  5. {There's no documentation or examples on how to do this in the Think 3.0 package.  I put roughly }
  6. {20 hours into making it work.  In order to assist othersin the same circumstance, I am putting these }
  7. {docs up on CIS.  Feel free to distribute them anywhere and to anyone.}
  8. {}
  9. {Key #1 is to make sure both panes are enclosed in the scroll pane.  Otherwise the pane that isn't will}
  10. {draw itself on top of your scroll bars.}
  11. {}
  12. {Key #2 is to make both panes sized sizELASTIC, both horizontally and vertically, even though one of}
  13. {them is to be fixed at the top of the window.  If you don't then once again that pane will draw itself}
  14. {on top of your scroll bars.}
  15. {}
  16. {Key #3 is to only attach one of the two panes to the scroll pane with InstallPanorama, namely, the}
  17. {pane that is to scroll in both directions.  Otherwise you won't be able to get your scroll bars to}
  18. {activate.}
  19. {}
  20. {Key #4 is to make a subclass of cScrollPane and to install your panes in it (see above) rather than}
  21. {in a normal scrollpane.  Then you override the  DoThumbDrag and DoHorizScroll procedures, adding}
  22. {code that scrolls the second pane.}
  23.  
  24. {Examples are enclosed below.  I have also enclosed a screen dump that illustrates the final working}
  25. {window.  I hope this saves you all the work it saved me!}
  26.  
  27. {Vik Rubenfeld}
  28. {9/21/90}
  29.  
  30.  
  31.  
  32. {INTERFACE FILE}
  33.  
  34. CQuesDataDoc = object(CDocument)
  35.  
  36.     { Declare your document's instance variables here     }
  37.         RecursionLevel: Integer;
  38.         ThisQuestion, HeadQuestion, FootQuestion: HandleToQuestion;
  39.         ThisAnswerLabel: HandleToAnswerLabel;
  40.         ThisQText: HandleToQText;
  41.  
  42.         DisplayMode: QuestionnaireDisplayModes;
  43.         itsDialog: DialogPtr;
  44.  
  45.         itsSourceFile: cSourceFile;
  46.         itsTargetFile: cTargetFile;
  47.  
  48.         itsQuesDataPane: CQuesDataPane;
  49.         itsHeader: cPicture;
  50.         itsScrollPane: cQuesDataScrollPane;
  51.  
  52.     { CQuesDataDoc's methods follow:                        }
  53.     end;
  54.  
  55. cQuesDataScrollPane = object(cScrollPane)
  56.         procedure DoHorizScroll (whichPart: integer);
  57.         override;
  58.  
  59.         procedure DoVertScroll (whichPart: integer);
  60.         override;
  61.  
  62.         procedure DoThumbDrag (hDelta: integer;
  63.                                     vDelta: integer);
  64.         override;
  65.     end;
  66.  
  67.  
  68. {DOCUMENT FILE}
  69. procedure CQuesDataDoc.BuildWindow (theData: Handle);
  70.     var
  71.         theWindow: cWindow;
  72.         theScrollPane: cQuesDataScrollPane;
  73.         thePanorama: cPanorama;
  74.         theMainPane: cPane;
  75.         theQuesDataPane: cQuesDataPane;
  76.         theHeader: cPicture;
  77. begin
  78.     new(theWindow);
  79.     itsWindow := theWindow;
  80.     itsWindow.IWindow(WINDQuesData, TRUE, gDesktop, SELF);
  81.  
  82.     new(theScrollPane);
  83.     itsScrollPane := theScrollPane;
  84.     itsScrollPane.IScrollPane(itsWindow, SELF, 10, 10, 0, 0, sizELASTIC, sizELASTIC, TRUE, TRUE, TRUE);
  85.     itsScrollPane.FitToEnclFrame(TRUE, TRUE);
  86.     itsScrollPane.SetWantsClicks(true);
  87.  
  88.     new(theQuesDataPane);
  89.     itsQuesDataPane := theQuesDataPane;
  90.     itsQuesDataPane.IQuesDataPane(itsScrollPane, SELF, 0, 0, 0, 0, sizELASTIC, sizELASTIC);
  91.     itsQuesDataPane.FitToEnclosure(TRUE, TRUE);
  92.     itsQuesDataPane.SetWantsClicks(true);
  93.  
  94.     new(theHeader);
  95.     itsHeader := theHeader;
  96.     itsHeader.IPicture(itsScrollPane, SELF, 0, 15, 0, 0, sizELASTIC, sizFIXEDTOP);
  97.     itsHeader.FitToEnclosure(true, false);
  98.     GetLineHeight(LineHeight, Monaco, 9);
  99.     itsHeader.SetScales(LineHeight, LineHeight);
  100.     itsHeader.SetWantsClicks(false);
  101.  
  102.     itsScrollPane.InstallPanorama(theQuesDataPane);
  103.  
  104.     itsMainPane := itsQuesDataPane;
  105.     itsGopher := itsQuesDataPane;
  106.     gGopher := itsQuesDataPane; {DON'T FORGET ABOUT gGOPHER}
  107. end;
  108.  
  109. procedure cQuesDataDoc.SetBoundsForQuestionData;
  110.     var
  111.         LineHeight: Integer;
  112.         RectForSetBounds: Rect;
  113.         I: Integer;
  114.         itsHeader: cPane;
  115.         theRect: Rect;
  116.  
  117. begin
  118.     GetLineHeight(LineHeight, Monaco, 9);
  119.     itsQuesDataPane.GetBounds(RectForSetBounds);
  120.  
  121.     S := ThisQuestion^^.NumberOfRows; {NumberOfRows is specific to my app.  Replace it with a}
  122. {variable that contains the number of lines of text in your document}
  123.  
  124.     I := Num2Integer(Str2Num(S));
  125.     RectForSetBounds.Bottom := I;
  126.     RectForSetBounds.Right := 475 div LineHeight; {You might want to replace 475 with a global}
  127. {constant.}
  128.  
  129. end;
  130.  
  131. itsQuesDataPane.SetBounds(RectForSetBounds);
  132. end;
  133.  
  134.  
  135. procedure CQuesDataDoc.SetDisplayMode (RequestedMode: QuestionnaireDisplayModes);
  136.     var
  137.         theRect: Rect;
  138.  
  139. begin
  140.     if DisplayMode <> RequestedMode then
  141.         begin
  142.             DisplayMode := RequestedMode;
  143.  
  144.             SetBoundsForQuestionData;
  145.  
  146.             SetRect(theRect, 0, 16, 0, 0);
  147.  
  148.             itsQuesDataPane.ChangeSize(theRect, true);
  149.  
  150.             itsHeader.UsePict(3010);
  151.             itsHeader.Draw(theRect);
  152.         end;
  153. end;
  154.  
  155. {THE SUBCLASS OF CSCROLLPANE}
  156. unit cQuesDataScrollPane;
  157.  
  158. interface
  159.  
  160.     uses
  161.         TCL, SANE, QuesDataIntf, cBufferedFile;
  162.  
  163. implementation
  164.     procedure cQuesDataScrollPane.DoHorizScroll (whichPart: integer);
  165.         var
  166.             delta,                        { Number of pixels to scroll        }
  167.             oldValue,                    { Current scroll bar setting        }
  168.             minmax: integer;        { Minimum or Maximum delta        }
  169.             ticks: longint;            { Tick count at end of Delay        }
  170.     begin
  171.         case whichPart of
  172.  
  173.             inUpButton: 
  174.                 delta := -hStep;
  175.  
  176.             inDownButton: 
  177.                 delta := hStep;
  178.  
  179.             inPageUp: 
  180.                 begin
  181.                     delta := hOverlap - hSpan;
  182.                 end;
  183.  
  184.             inPageDown: 
  185.                 begin
  186.                     delta := hSpan - hOverlap;
  187.                 end;
  188.         end;
  189.  
  190.         oldValue := itsHorizSBar.GetValue;
  191.         if delta < 0 then
  192.             begin
  193.                 minmax := itsHorizSBar.GetMinValue - oldValue;
  194.                 if delta < minmax then
  195.                     delta := minmax;
  196.  
  197.             end
  198.         else
  199.             begin
  200.                 minmax := itsHorizSBar.GetMaxValue - oldValue;
  201.                 if delta > minmax then
  202.                     delta := minmax;
  203.             end;
  204.  
  205.         if delta <> 0 then
  206.             gQuesDataDoc.itsHeader.Scroll(delta, 0, TRUE);
  207.  
  208.         inherited DoHorizScroll(whichPart);
  209.     end;
  210.  
  211.     procedure cQuesDataScrollPane.DoVertScroll (whichPart: integer);
  212.     begin
  213.         inherited DoVertScroll(whichPart);
  214.     end;
  215.  
  216.     procedure cQuesDataScrollPane.DoThumbDrag (hDelta: integer;
  217.                                     vDelta: integer);
  218.     begin
  219.         if hDelta <> 0 then
  220.             gQuesDataDoc.itsHeader.Scroll(hDelta, 0, TRUE);
  221.         inherited DoThumbDrag(hDelta, vDelta);
  222.     end;
  223. end.